package com.sunlong.jiangwei.entity;

import com.sunlong.jiangwei.vo.JwSkuVo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.elasticsearch.annotations.Document;
import tk.mybatis.mapper.annotation.KeySql;

import javax.persistence.Id;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;

/**
 * <p>
 *
 * </p>
 *
 * @author 孙龙
 * @since 2021-02-19
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class JwSku implements Serializable {


    /**
     * sku id
     */
    @Id
    @KeySql(useGeneratedKeys = true)
    private Long skuId;

    /**
     * spu id
     */
    private Long spuId;

    /**
     * 商品标题
     */
    private String skuTitle;

    /**
     * 商品的图片，多个图片以‘,’分割
     */
    private String skuImages;

    /**
     * 销售价格，单位为分
     */
    private Long skuPrice;

    /**
     * 特有规格属性在spu属性模板中的对应下标组合
     */
    private String skuIndexes;

    /**
     * sku的特有规格参数键值对，json格式，反序列化时请使用linkedHashMap，保证有序
     */
    private String skuOwnSpec;

    /**
     * 是否有效，0无效，1有效
     */
    private Boolean skuEnable;

    /**
     * 添加时间
     */
    private Date skuCreateTime;

    /**
     * 最后修改时间
     */
    private Date skuLastUpdateTime;

    /**
     * 库存数量
     */
    private Integer skuStock;


    public JwSku(Long skuId) {
        this.skuId = skuId;
    }

    public static JwSku getJwSku(Map<String, Object> objectMap) {
            JwSku jwSku = new JwSku();
            jwSku.setSkuId(((Integer)objectMap.get("skuId")).longValue());
            jwSku.setSkuPrice(((Integer)objectMap.get("skuPrice")).longValue());
            jwSku.setSkuOwnSpec((String) objectMap.get("skuOwnSpec"));
            jwSku.setSkuImages((String) objectMap.get("skuImages"));
            return jwSku;
    }
}
